import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/layout'
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  // 大屏页面
  // {
  //   path: '/iot',
  //   component: () => import('@/views/iot/index'),
  //   hidden: true
  // },
  {
    path: '/testpaper',
    component: () => import('@/views/testpaper/index'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '首页', icon: 'dashboard', affix: true }
      }
    ]
  },

  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () =>
  new Router({
    // 路由模式 默认是有#号
    mode: 'history',
    // 配置router的参数文件
    // base 参数 所有的请求都会在url之后加上这个参数
    // http://localhost:8080/base参数才能访问
    scrollBehavior: () => ({ y: 0 }),
    routes: [...constantRoutes, ...asyncRoutes]
  })
// 导入动态路由表 在父级目录写动态路由表
// 增删改查
import modality from './modules/modality'
// 效果案例
import result from './modules/result'
// 功能案例
import caselist from './modules/case'
// 档案
import canvas from './modules/canvas'
// 关联考试
import exam from './modules/exam'
// canvas
import installdevice from './modules/installdevice'
// 客服模块
import service from './modules/service'
// 流程配置
import flow from './modules/flow'

const asyncRoutes = [
  modality,
  result,
  caselist,
  canvas,
  exam,
  installdevice,
  service,
  flow
]

const router = createRouter()

export function resetRouter () {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
